Page({
    data:{
        detail:'',
        msg:'',
        id:''
    },
    onLoad:function(options){ 
        // 页面初始化 options为页面跳转所带来的参数  
        this.loadDetail(options.id); 
    },
    loadDetail:function(id){
        var page = this;
        console.log(id);
        wx.request({
          url: 'https://你的域名/API', //访问你服务器的API返回数据
          data: {id:id},
          method: 'GET',
          header:{
             'Content-Type':'application/json'
          },
          success: function(res){
              console.log(res.data);
              page.setData({detail:res.data});
              page.setData({id:id});
          }
        })
    },
    formSubmit: function(e) {
        var page = this;
        if(e.detail.value.username.length == 0){
            var msg = '*请填写完整信息';
            page.setData({msg:msg});   
        }else{
            //加载数据效果
            wx.showToast({
                title: '生成中',
                icon: 'loading',
                duration: 2000
            });
            console.log('----表单数据-----');
            console.log(e.detail.value.username);
            console.log(e.detail.value.id);
            var username = e.detail.value.username;
            var id = e.detail.value.id;
            wx.login({
                success:function(res){
                    if(res.code){
                        //发起网络请求
                        wx.request({
                            url:'https://你的域名/API', //code换取openid
                            data:{
                                code:res.code
                            },
                            success:function(res){
                                var json = JSON.parse(res.data);
                                console.log('-------openid---');
                                console.log(json.openid);
                                wx.request({
                                    url:https://你的域名/API', //访问你服务器的API返回数据
                                    data:{username:username,id:id,openid:json.openid},
                                    method:'GET',
                                    header:{
                                        'Content-Type':'application/json'
                                    },
                                    success:function(res){
                                        var imgUrl = res.data;
                                        console.log(res.data);
                                        wx.navigateTo({url:'../pic/pic?imgUrl='+imgUrl});
                                    }
                                });
                            }
                        })
                    }
                }
            }); 
        }     
    }
});